package client;

import javax.swing.JFrame;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import bean.Student;
import bean.Student_softwareEngineering;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import javax.swing.JLabel;

public class SpringClient extends JFrame{
	public SpringClient() {
		
		JPanel mainPanel = new JPanel();
		getContentPane().add(mainPanel, BorderLayout.CENTER);
		mainPanel.setLayout(new GridLayout(5, 0, 0, 0));
		
		JLabel lblIndexNewFactory = new JLabel("    创建一个spring框架的工厂");
		mainPanel.add(lblIndexNewFactory);
		
		JLabel lblNewFactory = new JLabel("    ApplicationContext act = new ClassPathXmlApplicationContext(\"applicationContext.xml\");");
		mainPanel.add(lblNewFactory);
		
		JLabel lblIndexNewStudent = new JLabel("    创建一个student bean,这里已经自带创建了一个 IPhone bean给student");
		mainPanel.add(lblIndexNewStudent);
		
		JLabel lblNewStudent = new JLabel("    Student student = (Student_softwareEngineering)act.getBean(\"quancheng\");");
		mainPanel.add(lblNewStudent);
		
		//创建一个spring框架的工厂
		ApplicationContext act = new ClassPathXmlApplicationContext("applicationContext.xml");
				
		//创建一个student bean,这里已经自带创建了一个 IPhone bean给student
		Student student = (Student_softwareEngineering)act.getBean("quancheng");
		String message = ((Student_softwareEngineering) student).getPhoneMessage();
		JLabel lblGetPhoneMessage = new JLabel("    这个学生"+message);
		mainPanel.add(lblGetPhoneMessage);
	}
	/**
	 * 
	 */
	private static final long serialVersionUID = 312953692558846428L;

	public static void main(String[] args) {
		SpringClient view = new SpringClient();
		view.setBounds(200, 200, 600, 200);
		
		view.setVisible(true);
	}
}
